package com.xunji.user.config;


import com.xunji.user.common.RedisUtil;
import com.xunji.user.service.CacheService;
import com.xunji.user.service.impl.MemCacheServiceImpl;
import com.xunji.user.service.impl.RedisCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class CacheConfig {

    @Bean
    @ConditionalOnProperty(value = "spring.redis.host")
    public CacheService redisCacheService(RedisUtil redisUtil/*, RedisTemplate<String, Object> redisTemplate*/) {
//        redisUtil.setRedisTemplate(redisTemplate);
        log.info("注入redis缓存实现");
        return new RedisCacheService(redisUtil);
    }

    @Bean
    @ConditionalOnMissingBean(value = CacheService.class)
    public CacheService memCacheService() {
        log.info("注入本地缓存实现");
        return new MemCacheServiceImpl();
    }
}
